package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import org.cfg.cache.DungeonLevelGroupCfgCache;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import org.cfg.cache.DungeonLevelCfgCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 副本关卡
 */
public class DungeonLevelCfg extends BaseCfg<DungeonLevelCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "dungeon_level";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.DungeonLevelCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 12;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","前置关卡id","难度","消耗资源","可进入次数","奖励","关卡时长","关卡评价条件类型","关卡评价条件参数","玩家等级","关卡组id","首战奖励",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","preLevelId","difficulty","cost","fightCount","reward","time","starType","starParam","playerLv","levelGroupId","firstReward",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","preLevelId","difficulty","cost","fightCount","reward","time","starType","starParam","playerLv","levelGroupId","firstReward",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,1238567836,1829500859,3059661,944521951,-934326481,3560141,1315868844,2132821339,1879273547,1572543446,-1075426817,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","int","Map","int","int","int","int[]","int[]","int","int","int",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Integer.class,Map.class,Integer.class,Integer.class,Integer.class,int[].class,int[].class,Integer.class,Integer.class,Integer.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 前置关卡id
	 */
	private int preLevelId;
	
	/**
	 * 难度
	 */
	private int difficulty;
	
	/**
	 * 消耗资源
	 */
	private Map cost;
	
	/**
	 * 可进入次数
	 */
	private int fightCount;
	
	/**
	 * 奖励
	 */
	private int reward;
	
	/**
	 * 关卡时长
	 */
	private int time;
	
	/**
	 * 关卡评价条件类型
	 */
	private int[] starType;
	
	/**
	 * 关卡评价条件参数
	 */
	private int[] starParam;
	
	/**
	 * 玩家等级
	 */
	private int playerLv;
	
	/**
	 * 关卡组id
	 */
	private int levelGroupId;
	
	/**
	 * 首战奖励
	 */
	private int firstReward;
	
	
	
	public static DungeonLevelCfg builder() {
		DungeonLevelCfg dungeonLevelCfg = new DungeonLevelCfg();
		return dungeonLevelCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 前置关卡id
	 */
	public int getPreLevelId() {
		return preLevelId;
	}
	
	/**
	 * 难度
	 */
	public int getDifficulty() {
		return difficulty;
	}
	
	/**
	 * 消耗资源
	 */
	public Map getCost() {
		return cost;
	}
	
	/**
	 * 可进入次数
	 */
	public int getFightCount() {
		return fightCount;
	}
	
	/**
	 * 奖励
	 */
	public int getReward() {
		return reward;
	}
	
	/**
	 * 关卡时长
	 */
	public int getTime() {
		return time;
	}
	
	/**
	 * 关卡评价条件类型
	 */
	public int[] getStarType() {
		return starType;
	}
	
	/**
	 * 关卡评价条件参数
	 */
	public int[] getStarParam() {
		return starParam;
	}
	
	/**
	 * 玩家等级
	 */
	public int getPlayerLv() {
		return playerLv;
	}
	
	/**
	 * 关卡组id
	 */
	public int getLevelGroupId() {
		return levelGroupId;
	}
	
	/**
	 * 首战奖励
	 */
	public int getFirstReward() {
		return firstReward;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.preLevelId;
        values[2] = this.difficulty;
        values[3] = this.cost;
        values[4] = this.fightCount;
        values[5] = this.reward;
        values[6] = this.time;
        values[7] = this.starType;
        values[8] = this.starParam;
        values[9] = this.playerLv;
        values[10] = this.levelGroupId;
        values[11] = this.firstReward;
        return values;
	}
	
	protected DungeonLevelCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.preLevelId = (int)vals[1];
		this.difficulty = (int)vals[2];
		this.cost = (Map)vals[3];
		this.fightCount = (int)vals[4];
		this.reward = (int)vals[5];
		this.time = (int)vals[6];
		this.starType = (int[])vals[7];
		this.starParam = (int[])vals[8];
		this.playerLv = (int)vals[9];
		this.levelGroupId = (int)vals[10];
		this.firstReward = (int)vals[11];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.preLevelId);
        map.put(keys[2], this.difficulty);
        map.put(keys[3], this.cost);
        map.put(keys[4], this.fightCount);
        map.put(keys[5], this.reward);
        map.put(keys[6], this.time);
        map.put(keys[7], this.starType);
        map.put(keys[8], this.starParam);
        map.put(keys[9], this.playerLv);
        map.put(keys[10], this.levelGroupId);
        map.put(keys[11], this.firstReward);
        return map;
    }
    
    protected DungeonLevelCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.preLevelId = (int)map.get(keys[1]);
   		this.difficulty = (int)map.get(keys[2]);
   		this.cost = (Map)map.get(keys[3]);
   		this.fightCount = (int)map.get(keys[4]);
   		this.reward = (int)map.get(keys[5]);
   		this.time = (int)map.get(keys[6]);
   		this.starType = (int[])map.get(keys[7]);
   		this.starParam = (int[])map.get(keys[8]);
   		this.playerLv = (int)map.get(keys[9]);
   		this.levelGroupId = (int)map.get(keys[10]);
   		this.firstReward = (int)map.get(keys[11]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.preLevelId);
        obj.put(keys[2], this.difficulty);
        obj.put(keys[3], this.cost);
        obj.put(keys[4], this.fightCount);
        obj.put(keys[5], this.reward);
        obj.put(keys[6], this.time);
        obj.put(keys[7], this.starType);
        obj.put(keys[8], this.starParam);
        obj.put(keys[9], this.playerLv);
        obj.put(keys[10], this.levelGroupId);
        obj.put(keys[11], this.firstReward);
        return obj;
    }
    
    protected DungeonLevelCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.preLevelId = obj.getIntValue(keys[1]);
	    this.difficulty = obj.getIntValue(keys[2]);
		this.cost = obj.getObject(keys[3],Map.class);
	    this.fightCount = obj.getIntValue(keys[4]);
	    this.reward = obj.getIntValue(keys[5]);
	    this.time = obj.getIntValue(keys[6]);
		this.starType = obj.getObject(keys[7],int[].class);
		this.starParam = obj.getObject(keys[8],int[].class);
	    this.playerLv = obj.getIntValue(keys[9]);
	    this.levelGroupId = obj.getIntValue(keys[10]);
	    this.firstReward = obj.getIntValue(keys[11]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.preLevelId);
	    byteBuf.writeInt(this.difficulty);
	    byteBuf.writeObject(this.cost);
	    byteBuf.writeInt(this.fightCount);
	    byteBuf.writeInt(this.reward);
	    byteBuf.writeInt(this.time);
	    byteBuf.writeObject(this.starType);
	    byteBuf.writeObject(this.starParam);
	    byteBuf.writeInt(this.playerLv);
	    byteBuf.writeInt(this.levelGroupId);
	    byteBuf.writeInt(this.firstReward);
    }
	
	protected DungeonLevelCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.preLevelId = byteBuf.readInt(null);
	    this.difficulty = byteBuf.readInt(null);
	    this.cost = (Map)byteBuf.readObject();
	    this.fightCount = byteBuf.readInt(null);
	    this.reward = byteBuf.readInt(null);
	    this.time = byteBuf.readInt(null);
	    this.starType = byteBuf.readIntArray(null);
	    this.starParam = byteBuf.readIntArray(null);
	    this.playerLv = byteBuf.readInt(null);
	    this.levelGroupId = byteBuf.readInt(null);
	    this.firstReward = byteBuf.readInt(null);
	    return this;
	}
	
	public DungeonLevelCfg deepCopy(){
		DungeonLevelCfg dungeonLevelCfg = null;
		try {
			dungeonLevelCfg = (DungeonLevelCfg) super.clone();
		    dungeonLevelCfg.cost = ToolCopy.copyObject(this.cost);
		    dungeonLevelCfg.starType = ToolCopy.copyObject(this.starType);
		    dungeonLevelCfg.starParam = ToolCopy.copyObject(this.starParam);
			return dungeonLevelCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return dungeonLevelCfg;
	}
//自定义内容起始位置
	/**
	 * 获取副本类型
	 */
	public int getDungeonType() {
		return getDungeonLevelGroupCfg().getDungeonType();
	}

	/**
	 * 获取副本组配置
	 */
	public DungeonLevelGroupCfg getDungeonLevelGroupCfg(){
		return DungeonLevelGroupCfgCache.me().getById(getLevelGroupId());
	}
//自定义内容结束位置
}
